import { CustomTableInterface } from '@/components/ProTable/interface';
import { PublicInterface } from '@/interface/public';
import { useContractInformationForm } from '../form/use-contractInformationForm';
import { RoleInterface } from '@/api/interface/auth/role';
import { RosterInterface } from '@/api/interface/personnel/roster/roster';

/**
 * 合同信息
 */

export function useContractInformationData(proTableBox: PublicInterface.ProTableValue, drawerObj: any) {
  const { contractInformationForm, saveAddContractInformationForm } = useContractInformationForm(proTableBox);

  let contractInformationData = reactive<CustomTableInterface<RosterInterface.ResContractInfoListByRosterId>>({
    initParam: {
      rosterId: ''
    },
    // 表格配置项
    columns: [
      { prop: 'operation', label: 'operation', fixed: 'left', width: 180 },
      {
        label: '开始日期',
        prop: 'start'
      },
      {
        label: '结束日期',
        prop: 'end'
      },
      {
        label: '年限',
        prop: 'ageLimit'
      },
      {
        label: '签订日期',
        prop: 'dateOfSigning'
      },

      {
        prop: 'remark',
        label: 'remark'
      }
    ],

    headButtonList: [
      {
        label: 'add',
        type: 'primary',
        icon: 'el-Plus',
        // permissionCode: 'roster:saveContract',
        methods: () => {
          const params = {
            rosterId: drawerObj.value.id
          };
          formOpen(contractInformationForm, '新增合同信息', params);
        }
      }
    ],
    rowButtonList: [
      {
        label: 'edit',
        type: 'primary',
        // permissionCode: 'roster:saveContract',
        methods: row => {
          const params = {
            rosterId: drawerObj.value.id,
            ...row
          };
          formOpen(contractInformationForm, '编辑合同信息', params);
        },
        attrs: {
          link: true
        }
      },
      {
        label: 'delete',
        type: 'danger',
        methods: row => {
          const name = `${transitionLanguages('button', 'delete')}【${row.dateOfSigning}】签订的合同信息`;
          const params = {
            id: row.id,
            rosterId: drawerObj.value.id
          };
          useHandleData(contractInfoDelete, params, name, proTableBox.value?.getTableList);
        },
        attrs: {
          link: true
        }
      }
    ]
  });

  return { contractInformationData, contractInformationForm, saveAddContractInformationForm };
}
